from django.contrib import admin

from project.models import Project, ProjectMember, ProjectRepository, ProjectIssue, ProjectTask, ProjectVersion

admin.site.site_header = '光亮项目管理'  # 设置header
admin.site.site_title = '光亮项目管理'  # 设置title
admin.site.index_title = '光亮项目管理'


@admin.register(Project)
class ProjectAdmin(admin.ModelAdmin):
    list_display = ['id', 'name', 'desc', 'status', 'create_time', 'update_time']
    list_display_links = ['name']
    list_filter = ['status']
    search_fields = ['name', 'desc']
    list_editable = ['status']
    date_hierarchy = 'create_time'
    ordering = ['id']
    fields = ['name', 'desc', 'status']


@admin.register(ProjectMember)
class ProjectMemberAdmin(admin.ModelAdmin):
    list_display = ['id', 'project', 'user', 'role', 'create_time']
    list_display_links = ['project']
    list_filter = ['role']
    search_fields = ['project__name', 'user__username']
    list_editable = ['role']
    date_hierarchy = 'create_time'
    ordering = ['id']
    fields = ['project', 'user', 'role']


@admin.register(ProjectRepository)
class ProjectRepositoryAdmin(admin.ModelAdmin):
    list_display = ['id', 'project', 'name', 'url', 'create_time']
    list_display_links = ['project']
    search_fields = ['project__name', 'name']
    date_hierarchy = 'create_time'
    ordering = ['id']
    fields = ['project', 'name', 'url']

# 项目问题
@admin.register(ProjectIssue)
class ProjectIssueAdmin(admin.ModelAdmin):
    list_display = ['id', 'project', 'name', 'desc', 'status', 'create_time']
    list_display_links = ['project']
    list_filter = ['status']
    search_fields = ['project__name', 'name', 'desc']
    list_editable = ['status']
    date_hierarchy = 'create_time'
    ordering = ['id']
    fields = ['project', 'name', 'desc', 'status']


# 项目任务
@admin.register(ProjectTask)
class ProjectTaskAdmin(admin.ModelAdmin):
    list_display = ['id', 'project', 'name', 'desc', 'status', 'create_time']
    list_display_links = ['project']
    list_filter = ['status']
    search_fields = ['project__name', 'name', 'desc']
    list_editable = ['status']
    date_hierarchy = 'create_time'
    ordering = ['id']
    fields = ['project', 'name', 'desc', 'status']


# 项目版本
@admin.register(ProjectVersion)
class ProjectVersionAdmin(admin.ModelAdmin):
    list_display = ['id', 'project', 'name', 'desc', 'status', 'create_time']
    list_display_links = ['project']
    list_filter = ['status']
    search_fields = ['project__name', 'name', 'desc']
    list_editable = ['status']
    date_hierarchy = 'create_time'
    ordering = ['id']
    fields = ['project', 'name', 'desc', 'status']